import { Component, OnInit,Output,Input,EventEmitter,ViewChild } from '@angular/core';
import {Service} from '../../../server/server';
import {HttpClient} from '@angular/common/http';
import {CudTableService} from '../../../public/serve/cud-table/cud-table.service';
import {RemoveTableService} from '../../../public/serve/remove-table/remove-table.service';
import {keywordTableAddtype} from '../../../system/keyword-table-management/keywordtable.data';
import {InternalIndexedModalTableComponent} from '../../internal-indexed-modal-table/internal-indexed-modal-table.component';
import {HintsService} from '../../../public/serve/hints/hints.service';
import {InitService} from '../../../public/serve/init/init.service';
import { ActivatedRoute,Params } from '@angular/router';
import {InternalIndexedModalRelthemeComponent} from '../../internal-indexed-modal-reltheme/internal-indexed-modal-reltheme.component';
import {InternalIndexedModalTableVersionComponent} from '../../internal-indexed-modal-table-version/internal-indexed-modal-table-version.component';
import { internal } from '../../internal.data';
declare var $:any;

@Component({
  selector: 'app-time-attribute',
  templateUrl: './time-attribute.component.html',
  styleUrls: ['./time-attribute.component.css']
})
export class TimeAttributeComponent implements OnInit {

  @Input() internalParam : any;
  public tabVal: any;

  pageNo : number = 1;
  pageSize : number = 200;
  total      : number = 0;
  naturalNum : number = 0;
  productId:any;
  searchData:any;
  public onProductTimeMetaEmit: any;

  constructor(
    private server: Service,
    public request: CudTableService,
    private tableListService: CudTableService,
    private hintsService: HintsService,
    private removeTableService: RemoveTableService,
    public initService: InitService,
    private http: HttpClient,
    private activatedRoute: ActivatedRoute,
  ) { }

  ngOnInit() {
    this.onProductTimeMetaEmit = this.server.onProductTimeMetaEmit.subscribe((value: any) => {
      this.getProductTimeMetaList();
    });
  }

  public getAttributeData(pid){
    this.productId = pid;
    this.getProductTimeMetaList();
  }

  /**
     * 查询时间属性列表
     */
    public getProductTimeMetaList(){
      let url = this.server.baseUrl + 'Service/IdxProduct/getProductTimeMetaList';
      let data = this._tableData();
      this.request.postRequest(url,data).then((res:any) => {
          if (res.result_code === '0000') {
              this.tabVal = res.result; 
              this.total = res.length;
          }
      })
      .catch((err: any)=>{
          return;
      });
    }

  //查询参数
  private _tableData(){
    return {
      token         : internal.retrieval.token,
      pageNo        : this.pageNo,
      pageSize      : this.pageSize,
      productId     : this.productId,
      queryCriteria : this.searchData
    }
  }

  /**
   * 分页
   * @param pagination 
   */ 
  _pagination(pagination: Array<any>) {
    this.pageNo = pagination[0].pageNumber;
    this.pageSize   = pagination[0].pageSize;
    this.naturalNum = (this.pageNo - 1) * this.pageSize;
    this.getProductTimeMetaList();
  }

  //搜索
  search() {
    this.searchData = this.searchData;
    this.getProductTimeMetaList();
  }
  //响应搜索
  changesearch() {
      this.search();
  }

}
